package com.longxi.tianjintianbao.ui.adapter.multitype.completeEnter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.RadioButton;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.SelectEnterStateListener;
import com.longxi.tianjintianbao.model.completeEnter.EnterState;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class EnterStateViewBinder extends ItemViewBinder<EnterState, EnterStateViewBinder.ViewHolder> {

    SelectEnterStateListener listener;
    public EnterStateViewBinder(SelectEnterStateListener selectEnterStateListener) {
        listener = selectEnterStateListener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_enter_state, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull EnterState enterState) {
        holder.mRBtnState.setText(enterState.getStateName());
        holder.mRBtnState.setChecked(enterState.isSelect());
        holder.mRBtnState.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onSuccess(enterState);
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        RadioButton mRBtnState;
        ViewHolder(View itemView) {
            super(itemView);
            mRBtnState = itemView.findViewById(R.id.rBtnState);
        }
    }
}
